<template>
  <div class="common_block_div">
    <div class="search_area">
      <el-form :model="queryParams" ref="queryForm" class="margin_t10 search_form" label-width="90px">
        <el-row class="flex flex_w">
          <FormItem label="关键字" class="" type="input" :form="queryParams" @keyenter="handleQuery" prop="keywords"
            placeholder="请输入关键字" clearable />
          <FormItem label="状态" class="" type="select" :form="queryParams" prop="status" :seleDatas="statusOptions"
          seleKey="value" seleName="label" clearable filterable />
          <div class="common_button margin_l20">
            <div class="right_button flex">
              <a href="javascript:;" class="color_blue" @click="handleQuery">查询</a>
              <a href="javascript:;" class="color_dark" @click="resetQuery">重置</a>
            </div>
          </div>
        </el-row>
      </el-form>
    </div>

    <!-- 操作按钮 -->
    <div class="common_button flex_ac">
      <div class="right_button margin_a flex">
        <a href="javascript:;" class="color_blue " @click="handleAdd" v-if="have_auth('/project/index/add')">新增</a>
      </div>
    </div>

    <el-table v-loading="loading" :data="list">
      <el-table-column label="集合编号" prop="id" width="80" />
      <el-table-column label="项目编号" prop="project_no" width="180" />
      <el-table-column label="项目标题" :show-overflow-tooltip="true" width="300">
        <template slot-scope="scope">
          <span
            style="color: #325FFF; cursor: pointer;"
            @click="handleDetail(scope.row)"
            :title="scope.row.title">
            {{ scope.row.title || '-' }}
          </span>
        </template>
      </el-table-column>
      <el-table-column label="提交总数" prop="all_num" sortable width="100" />
      <el-table-column label="已审核" prop="sh_success_num" sortable width="100" />
      <el-table-column label="已评分" prop="pw_complate_num" sortable width="100" />
      <el-table-column label="状态" prop="status_text" width="120">
        <template slot-scope="scope">
          <span :style="{ color: scope.row.status_text_color }">
            {{ scope.row.status_text }}
          </span>
        </template>
      </el-table-column>
      <el-table-column label="申报时间" width="200">
        <template slot-scope="scope">
          {{ scope.row.begin_time }} - {{ scope.row.end_time }}
        </template>
      </el-table-column>
      <el-table-column label="评分时间" width="200">
        <template slot-scope="scope">
          {{ scope.row.pw_df_begin_time }} - {{ scope.row.pw_df_end_time }}
        </template>
      </el-table-column>
      <el-table-column label="操作" width="250px" fixed="right">
        <template slot-scope="scope">
          <el-button size="mini" type="text" @click="handleDetail(scope.row)" v-if="have_auth('/project/index/detail')">查看</el-button>
          <el-button v-if="[0, 20].includes(scope.row.status) && have_auth('/project/index/edit')" size="mini" type="text"
            @click="handleUpdate(scope.row)">编辑</el-button>
          <el-button v-if="[0].includes(scope.row.status) && have_auth('/project/index/open')" size="mini" type="text"
            @click="handlePublish(scope.row)">公开</el-button>
          <el-button v-if="[20].includes(scope.row.status)  && have_auth('/project/index/pause')" size="mini" type="text"
            @click="handlePause(scope.row)">暂停</el-button>
          <el-button v-if="[20].includes(scope.row.status) && have_auth('/project/index/end')" size="mini" type="text"
            @click="handleFinish(scope.row)">完结</el-button>
          <el-button v-if="[40].includes(scope.row.status)  && have_auth('/project/index/huifu')" size="mini" type="text"
            @click="handleResume(scope.row)">恢复</el-button>
          <el-button size="mini" type="text" @click="handleDelete(scope.row)" v-if="have_auth('/project/index/del')">删除</el-button>
          <el-button size="mini" type="text" @click="handleAnswer(scope.row)" v-if="have_auth('/project/index/answer')">预览答题</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.page" :limit.sync="queryParams.limit"
      @pagination="getList" />

    <!-- 添加或修改对话框 -->
    <el-dialog v-dialogDrag :close-on-click-modal="false" :title="form.id ? '编辑项目' : '新增项目'" :visible.sync="open"
      width="800px" append-to-body top="5vh" @closed="handleDialogClosed">
      <el-form ref="form" :model="form" :rules="rules" label-width="140px">
        <el-row :gutter="20">
          <!-- 项目标题 -->
          <el-col :span="24">
            <el-form-item label="项目标题" prop="title">
              <el-input v-model="form.title" clearable placeholder="请输入项目标题" maxlength="50" show-word-limit />
            </el-form-item>
          </el-col>

          <!-- 项目开始时间、结束时间 -->
          <el-col :span="12">
            <el-form-item label="项目开始时间" prop="begin_time">
              <el-date-picker v-model="form.begin_time" type="date" value-format="yyyy-MM-dd" placeholder="选择项目开始时间"
                style="width: 100%" clearable :picker-options="{
                  disabledDate: (time) => {
                    if (form.end_time) {
                      // 允许选择同一天，只禁用大于结束时间的日期
                      const endTime = new Date(form.end_time);
                      endTime.setHours(0, 0, 0, 0);
                      const currentTime = new Date(time);
                      currentTime.setHours(0, 0, 0, 0);
                      return currentTime.getTime() > endTime.getTime();
                    }
                    return false;
                  }
                }"></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="项目结束时间" prop="end_time">
              <el-date-picker v-model="form.end_time" type="date" value-format="yyyy-MM-dd" placeholder="选择项目结束时间"
                style="width: 100%" clearable :picker-options="{
                  disabledDate: (time) => {
                    if (form.begin_time) {
                      // 允许选择同一天，只禁用小于开始时间的日期
                      const beginTime = new Date(form.begin_time);
                      beginTime.setHours(0, 0, 0, 0);
                      const currentTime = new Date(time);
                      currentTime.setHours(0, 0, 0, 0);
                      return currentTime.getTime() < beginTime.getTime();
                    }
                    return false;
                  }
                }"></el-date-picker>
            </el-form-item>
          </el-col>

          <!-- 评委打分开始时间、结束时间 -->
          <el-col :span="12">
            <el-form-item label="评委打分开始时间" prop="pw_df_begin_time">
              <el-date-picker v-model="form.pw_df_begin_time" type="date" value-format="yyyy-MM-dd"
                placeholder="选择评委打分开始时间" style="width: 100%" clearable :picker-options="{
                  disabledDate: (time) => {
                    if (form.pw_df_end_time) {
                      // 允许选择同一天，只禁用大于结束时间的日期
                      const endTime = new Date(form.pw_df_end_time);
                      endTime.setHours(0, 0, 0, 0);
                      const currentTime = new Date(time);
                      currentTime.setHours(0, 0, 0, 0);
                      return currentTime.getTime() > endTime.getTime();
                    }
                    return false;
                  }
                }"></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="评委打分结束时间" prop="pw_df_end_time">
              <el-date-picker v-model="form.pw_df_end_time" type="date" value-format="yyyy-MM-dd"
                placeholder="选择评委打分结束时间" style="width: 100%" clearable :picker-options="{
                  disabledDate: (time) => {
                    if (form.pw_df_begin_time) {
                      // 允许选择同一天，只禁用小于开始时间的日期
                      const beginTime = new Date(form.pw_df_begin_time);
                      beginTime.setHours(0, 0, 0, 0);
                      const currentTime = new Date(time);
                      currentTime.setHours(0, 0, 0, 0);
                      return currentTime.getTime() < beginTime.getTime();
                    }
                    return false;
                  }
                }"></el-date-picker>
            </el-form-item>
          </el-col>

          <!-- 基础权重分、评委权重分 -->
          <el-col :span="12">
            <el-form-item label="基础权重分" prop="base_score_rate">
              <el-input-number v-model="form.base_score_rate" :min="0" :max="100" :step="1" :precision="0"
                placeholder="请输入基础权重分" style="width: 100%" controls-position="right" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="评委权重分" prop="pw_score_rate">
              <el-input-number v-model="form.pw_score_rate" :min="0" :max="100" :step="1" :precision="0"
                placeholder="请输入评委权重分" style="width: 100%" controls-position="right" />
            </el-form-item>
          </el-col>

          <!-- 题库模板 -->
          <el-col :span="24">
            <el-form-item label="题库模板" prop="q_id">
              <div style="display: flex; align-items: center; gap: 10px;">
                <el-select v-model="form.q_id" clearable filterable placeholder="请选择题库模板" style="flex: 1;">
                  <el-option v-for="item in questionTemplateOptions" :key="item.id" :label="item.title"
                    :value="item.id"></el-option>
                </el-select>
                <el-button type="text" @click="handleGoToTemplate">去设置</el-button>
              </div>
            </el-form-item>
          </el-col>

          <!-- 填报口令 -->
          <el-col :span="24">
            <el-form-item label="填报口令" prop="kouling">
              <el-input v-model="form.kouling" clearable placeholder="请输入填报口令（选填）" />
            </el-form-item>
          </el-col>

          <!-- 附件上传 -->
          <el-col :span="24">
            <el-form-item label="附件">
              <div class="attachment_list margin_b10">
                <div v-for="(file, index) in attachmentList" :key="index" class="attachment_item flex_ac margin_b10"
                  style="padding: 8px; background: #f5f7fa; border-radius: 4px;">
                  <i class="el-icon-document margin_r10" style="color: #409EFF;"></i>
                  <span class="flex1" :title="file.file_name">{{ file.file_name }}</span>
                  <i class="el-icon-delete margin_l10" style="cursor: pointer; color: #F56C6C;"
                    @click="removeAttachment(index)"></i>
                </div>
              </div>
              <el-upload ref="upload" :action="uploadUrl" :headers="uploadHeaders" :on-success="handleUploadSuccess"
                :on-error="handleUploadError" :before-upload="beforeUpload" :auto-upload="true" :show-file-list="false"
                accept=".pdf,.doc,.docx,.xls,.xlsx,.ppt,.pptx">
                <el-button type="primary" icon="el-icon-upload" size="small">上传附件</el-button>
              </el-upload>
            </el-form-item>
          </el-col>

          <!-- 项目介绍 -->
          <el-col :span="24">
            <el-form-item label="项目介绍" prop="content">
              <Editor v-model="form.content" :height="300" :min-height="200" upload-url="/api/Upload/image" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="handleDialogClose">取 消</el-button>
        <el-button type="primary" @click="submitForm('form')" :loading="is_ajax">{{ is_ajax ? '保存中···' : '确定'
          }}</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
// 导入项目管理API
import projectApi from "@/api/project";
// 导入编辑器组件
import Editor from "@/components/Editor/index.vue";
export default {
  name: 'needCache',
  components: {
    Editor
  },
  data() {
    return {
      loading: true,
      total: 0,
      // 项目列表数据
      list: [],
      // 状态选项数据
      statusOptions: [],
      // 查询参数
      queryParams: {
        page: 1,
        limit: 16,
        keywords: '',
        status: ''
      },
      open: false,
      // 题库模板选项
      questionTemplateOptions: [],
      // 附件列表
      attachmentList: [],
      // 上传相关
      uploadUrl: '',
      uploadHeaders: {},
      // 表单参数
      form: {
        id: '',
        title: '', // 项目标题
        begin_time: '', // 项目开始时间
        end_time: '', // 项目结束时间
        pw_df_begin_time: '', // 评委打分开始时间
        pw_df_end_time: '', // 评委打分结束时间
        base_score_rate: null, // 基础权重分
        pw_score_rate: null, // 评委权重分
        q_id: '', // 题库模板
        arrr_data: [], // 附件ID数组
        content: '', // 项目介绍
        kouling: '' // 填报口令（不是必填）
      },
      // 表单校验
      rules: {
        title: [
          { required: true, message: "项目标题不能为空", trigger: "blur" }
        ],
        begin_time: [
          { required: true, message: "项目开始时间不能为空", trigger: "change" },
          {
            validator: (rule, value, callback) => {
              if (value && this.form.end_time) {
                // 允许选择同一天，只验证开始时间不能大于结束时间
                const beginDate = new Date(value);
                beginDate.setHours(0, 0, 0, 0);
                const endDate = new Date(this.form.end_time);
                endDate.setHours(0, 0, 0, 0);
                if (beginDate.getTime() > endDate.getTime()) {
                  callback(new Error('项目开始时间不能大于结束时间'));
                } else {
                  callback();
                }
              } else {
                callback();
              }
            },
            trigger: "change"
          }
        ],
        end_time: [
          { required: true, message: "项目结束时间不能为空", trigger: "change" },
          {
            validator: (rule, value, callback) => {
              if (value && this.form.begin_time) {
                // 允许选择同一天，只验证结束时间不能小于开始时间
                const beginDate = new Date(this.form.begin_time);
                beginDate.setHours(0, 0, 0, 0);
                const endDate = new Date(value);
                endDate.setHours(0, 0, 0, 0);
                if (endDate.getTime() < beginDate.getTime()) {
                  callback(new Error('项目结束时间不能小于开始时间'));
                } else {
                  callback();
                }
              } else {
                callback();
              }
            },
            trigger: "change"
          }
        ],
        pw_df_begin_time: [
          { required: true, message: "评委打分开始时间不能为空", trigger: "change" },
          {
            validator: (rule, value, callback) => {
              if (value && this.form.pw_df_end_time) {
                // 允许选择同一天，只验证开始时间不能大于结束时间
                const beginDate = new Date(value);
                beginDate.setHours(0, 0, 0, 0);
                const endDate = new Date(this.form.pw_df_end_time);
                endDate.setHours(0, 0, 0, 0);
                if (beginDate.getTime() > endDate.getTime()) {
                  callback(new Error('评委打分开始时间不能大于结束时间'));
                } else {
                  callback();
                }
              } else {
                callback();
              }
            },
            trigger: "change"
          }
        ],
        pw_df_end_time: [
          { required: true, message: "评委打分结束时间不能为空", trigger: "change" },
          {
            validator: (rule, value, callback) => {
              if (value && this.form.pw_df_begin_time) {
                // 允许选择同一天，只验证结束时间不能小于开始时间
                const beginDate = new Date(this.form.pw_df_begin_time);
                beginDate.setHours(0, 0, 0, 0);
                const endDate = new Date(value);
                endDate.setHours(0, 0, 0, 0);
                if (endDate.getTime() < beginDate.getTime()) {
                  callback(new Error('评委打分结束时间不能小于开始时间'));
                } else {
                  callback();
                }
              } else {
                callback();
              }
            },
            trigger: "change"
          }
        ],
        base_score_rate: [
          { required: true, message: "基础权重分不能为空", trigger: "change" },
          {
            validator: (rule, value, callback) => {
              const baseRate = Number(value) || 0;
              const pwRate = Number(this.form.pw_score_rate) || 0;
              if (baseRate + pwRate > 100) {
                callback(new Error('基础权重分和评委权重分之和不能大于100'));
              } else {
                callback();
              }
            },
            trigger: "change"
          }
        ],
        pw_score_rate: [
          { required: true, message: "评委权重分不能为空", trigger: "change" },
          {
            validator: (rule, value, callback) => {
              const baseRate = Number(this.form.base_score_rate) || 0;
              const pwRate = Number(value) || 0;
              if (baseRate + pwRate > 100) {
                callback(new Error('基础权重分和评委权重分之和不能大于100'));
              } else {
                callback();
              }
            },
            trigger: "change"
          }
        ],
        q_id: [
          { required: true, message: "题库模板不能为空", trigger: "change" }
        ],
        content: [
          { required: true, message: "项目介绍不能为空", trigger: "blur" }
        ]
      },
      is_ajax: false
    }
  },
  activated() {
    this.getList();
    this.getBaseData();
    this.getStatusData();
    // 初始化上传配置
    this.uploadUrl = this.http + '/manage/Attachment/upload';
    this.uploadHeaders = {
      'user-authorization': this.getState().token || ''
    };
  },
  methods: {
    handleDetail(row) {
      this.$router.push({ //核心语句
        path: '/project/detail?id=' + row.id,
      })
    },
    /** 跳转到设置模版 */
    handleGoToTemplate() {
      // 关闭对话框
      this.open = false;
      // 跳转到设置模版页面
      this.$router.push({
        path: '/answer/index'
      })
    },
    // 表单重置
    reset() {
      if (this.$refs['form']) {
        this.$refs['form'].clearValidate();
      }
    },
    /** 提交按钮 */
    submitForm: function (form) {
      const _this = this;
      this.$refs[form].validate(valid => {
        if (valid) {
          this.is_ajax = true;
          let _data = { ..._this[form] };
          // 处理附件ID数组
          _data.arrr_data = _this.attachmentList.map(item => item.id).filter(id => id);
          // 使用项目API创建或更新项目
          projectApi.createOrUpdate(_data).then(function (res) {
            if (res) {
              _this.tip_show('操作成功', 'success');
              _this.handleDialogClose();
              _this.getList()
            }
            _this.is_ajax = false;
          }).catch(function (error) {
            _this.is_ajax = false
            console.error('保存项目失败:', error);
          })
        }
      });
    },

    /** 获取基础数据 */
    getBaseData() {
      const _this = this;
      projectApi.getBaseData().then(function (res) {
        if (res && res.data) {
          const data = res.data;
          // 处理题库模板选项
          if (data.questionnaire_version_options) {
            const templates = data.questionnaire_version_options || [];
            _this.questionTemplateOptions = templates.map(item => ({
              id: item.id,
              title: item.title || item.name
            }));
          }
          // 如果有其他基础数据，可以在这里处理
          // 例如：权重选项、状态选项等
        }
      }).catch(function (error) {
        console.error('获取基础数据失败:', error);
      });
    },

    /** 附件上传成功 */
    handleUploadSuccess(res, file, fileList) {
      if (res && res.status == 200 && res.data) {
        const attachment = {
          id: res.data.attachment_id || res.data.id,
          file_name: file.name,
          file_url: res.data.file_url,
          file_size: file.size
        };
        this.attachmentList.push(attachment);
        this.$message.success('上传成功');
      } else {
        this.$message.error(res.message || '上传失败');
      }
    },

    /** 附件上传失败 */
    handleUploadError(err, file, fileList) {
      console.error('上传失败:', err);
      this.$message.error('上传失败，请重试');
    },

    /** 上传前验证 */
    beforeUpload(file) {
      const isValidType = ['application/pdf', 'application/msword',
        'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
        'application/vnd.ms-excel',
        'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
        'application/vnd.ms-powerpoint',
        'application/vnd.openxmlformats-officedocument.presentationml.presentation'].includes(file.type);
      const isLt10M = file.size / 1024 / 1024 < 10;

      if (!isValidType) {
        this.$message.error('只能上传 PDF、Word、Excel、PPT 格式的文件!');
        return false;
      }
      if (!isLt10M) {
        this.$message.error('文件大小不能超过 10MB!');
        return false;
      }
      return true;
    },

    /** 删除附件 */
    removeAttachment(index) {
      this.attachmentList.splice(index, 1);
    },

    /** 关闭对话框 */
    handleDialogClose() {
      // 先清除表单验证，避免显示错误提示
      if (this.$refs.form) {
        this.$refs.form.clearValidate();
      }
      // 关闭对话框
      this.open = false;
    },

    /** 对话框关闭后的回调 */
    handleDialogClosed() {
      // 在对话框完全关闭后重置表单数据，避免验证规则被触发
      this.$nextTick(() => {
        // 先清除表单验证
        if (this.$refs.form) {
          this.$refs.form.clearValidate();
        }
        // 再重置表单数据
        this.form = {
          id: '',
          title: '',
          begin_time: '',
          end_time: '',
          pw_df_begin_time: '',
          pw_df_end_time: '',
          base_score_rate: null,
          pw_score_rate: null,
          q_id: '',
          arrr_data: [],
          content: '',
          kouling: ''
        };
        this.attachmentList = [];
      });
    },

    /** 获取状态数据 */
    getStatusData() {
      const _this = this;
      projectApi.getStatusData().then(function (res) {
        if (res && res.message) {
          _this.statusOptions = res.message || [];
        } else if (res && res.data) {
          _this.statusOptions = res.data || [];
        }
      }).catch(function (error) {
        console.error('获取状态数据失败:', error);
      })
    },
    /** 查询项目列表 */
    getList() {
      const _this = this;
      this.loading = true;
      // 使用项目API获取列表
      projectApi.list(this.queryParams).then(function (res) {
        if (res && res.message) {
          _this.list = res.message.data || [];
          _this.total = res.message.total || 0;
        }
        _this.loading = false;
      }).catch(function (error) {
        console.error('获取项目列表失败:', error);
        _this.loading = false;
      })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.page = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.queryParams = {
        page: 1,
        limit: 16,
        keywords: '',
        status: ''
      }
      this.handleQuery();
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      // 重置表单数据
      this.form = {
        id: '',
        title: '',
        begin_time: '',
        end_time: '',
        pw_df_begin_time: '',
        pw_df_end_time: '',
        base_score_rate: null,
        pw_score_rate: null,
        q_id: '',
        arrr_data: [],
        content: '',
        kouling: ''
      };
      this.attachmentList = [];
      this.open = true;
    },

    /** 编辑按钮操作 */
    handleUpdate(row) {
      if (!row || !row.id) {
        this.$message.warning('请选择要编辑的项目');
        return;
      }
      this.reset();
      // 编辑模式：获取项目详情
      const _this = this;
      projectApi.detail({ id: row.id }).then(function (res) {
        if (res && res.data) {
          const data = res.data;
          _this.form = {
            id: data.id || '',
            title: data.title || '',
            begin_time: data.begin_time || '',
            end_time: data.end_time || '',
            pw_df_begin_time: data.pw_df_begin_time || '',
            pw_df_end_time: data.pw_df_end_time || '',
            base_score_rate: data.base_score_rate !== null && data.base_score_rate !== undefined ? Number(data.base_score_rate) : null,
            pw_score_rate: data.pw_score_rate !== null && data.pw_score_rate !== undefined ? Number(data.pw_score_rate) : null,
            q_id: data.q_id || '',
            arrr_data: data.arrr_data || [],
            content: data.content || '',
            kouling: data.kouling || ''
          };
          // 处理附件列表
          if (data.arrr_data_detail && data.arrr_data_detail.length > 0) {
            _this.attachmentList = data.arrr_data_detail.map(item => ({
              id: item.id,
              file_name: item.file_name,
              file_url: item.file_url,
              file_size: item.file_size || 0
            }));
          } else {
            _this.attachmentList = [];
          }
          _this.open = true;
        }
      }).catch(function (error) {
        console.error('获取项目详情失败:', error);
        _this.$message.error('获取项目详情失败');
      });
    },
    handleAnswer(row){
      this.$router.push({
        path: '/answer/projectanswer?type=2&project_id='+row.id
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const _this = this;
      if (!row || !row.id) {
        _this.$message.error('请选择要删除的数据');
        return false;
      }
      this.$confirm('是否确认删除?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function () {
        // 使用项目API删除项目
        projectApi.delete({ id: row.id }).then((res) => {
          if (res) {
            _this.getList();
            _this.$message.success('操作成功');
          }
        }).catch((err) => {
          console.error('删除项目失败:', err);
        });
      })
    },

    /** 暂停项目 */
    handlePause(row) {
      const _this = this;
      this.$confirm('是否确认暂停该项目?', "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function () {
        projectApi.pause({ id: row.id }).then((res) => {
          if (res) {
            _this.getList();
            _this.$message.success('暂停成功');
          }
        }).catch((err) => {
          console.error('暂停项目失败:', err);
          _this.$message.error('暂停失败');
        });
      }).catch(() => { });
    },

    /** 恢复项目 */
    handleResume(row) {
      const _this = this;
      this.$confirm('是否确认恢复该项目?', "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function () {
        projectApi.resume({ id: row.id }).then((res) => {
          if (res) {
            _this.getList();
            _this.$message.success('恢复成功');
          }
        }).catch((err) => {
          console.error('恢复项目失败:', err);
          _this.$message.error('恢复失败');
        });
      }).catch(() => { });
    },

    /** 公开项目 */
    handlePublish(row) {
      const _this = this;
      this.$confirm('是否确认公开该项目?', "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function () {
        projectApi.publish({ id: row.id }).then((res) => {
          if (res) {
            _this.getList();
            _this.$message.success('公开成功');
          }
        }).catch((err) => {
          console.error('公开项目失败:', err);
          _this.$message.error('公开失败');
        });
      }).catch(() => { });
    },

    /** 完结项目 */
    handleFinish(row) {
      const _this = this;
      this.$confirm('是否确认完结该项目?完结后项目将无法再进行操作。', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function () {
        projectApi.finish({ id: row.id }).then((res) => {
          if (res) {
            _this.getList();
            _this.$message.success('完结成功');
          }
        }).catch((err) => {
          console.error('完结项目失败:', err);
          _this.$message.error('完结失败');
        });
      }).catch(() => { });
    },

  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.search_btns {
  display: flex;
  align-items: center;
}
</style>
